<template>
  <div>
    <v-title></v-title>

    <van-field
      v-model="user.phone"
      label="请输入手机号"
      placeholder="请输入手机号"
      :rules="[{ required: true, message: '请输入手机号' }]"
    />
    <van-field
      v-model="user.password"
      type="password"
      label="请输入密码"
      placeholder="请输入密码"
      :rules="[{ required: true, message: '请输入密码' }]"
    />
    <div style="margin: 16px">
      <van-button type="primary" @click="tologin">登录</van-button>
      <van-button type="info" @click="toregister">去注册</van-button>
    </div>
  </div>
</template>


<script>
import { gologin } from "../request/app";
export default {
  data() {
    return {
      user: {
        phone: "",
        password: "",
      },
    };
  },
  methods: {
    tologin() {
      if (!this.user.phone || !this.user.password) {
        this.$toast("手机号或密码不能为空");
        return;
      }

      gologin(this.user).then((val) => {
        if (val.code != 200) {
          this.$toast(val.msg);
          return;
        }
        localStorage.setItem("info", JSON.stringify(val.list));
        this.$toast(val.msg);
        this.$router.push("/home");
      });

      this.user.phone = "";
      this.user.password = "";
    },
    toregister() {
      this.$router.push("/register");
    },
  },
};
</script>


<style scoped>
.van-button {
  margin-right: 0.2rem;
}
</style>